<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
<div id="content">
    <div id="icon" class="icon32"><br/></div><h2>编辑标签</h2>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">列表</a></li>
            <li><a href="#tabs-2">编辑</a></li>
        </ul>
        <div id="tabs-1">
            <table class="list-table">
                <thead class="ui-state-default">
                    <tr>
                        <th width="15%">ID</th>
                        <th width="55%">标签</th>
                        <th width="30%">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($this->tagList)) : ?>
                        <?php foreach ($this->tagList as $tag) : ?>
                    <tr>
                        <td><?php echo $this->escape($tag->tagId) ?></td>
                        <td><?php echo $this->escape($tag->tagName) ?></td>
                        <td>
                            <a href="javascript:void(0)" onclick="editTag(<?php echo $this->escape($tag->tagId) ?>)">编辑</a> |
                            <a href="javascript:if(confirm('确实要删除【<?php echo $this->escape($tag->tagName) ?>】标签吗?'))location='/backend/del/tag/id/<?php echo $this->escape($tag->tagId) ?>'">删除</a>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
                <tfoot class="ui-state-default">
                    <tr>
                        <th width="15%">ID</th>
                        <th width="55%">标签</th>
                        <th width="30%">操作</th>
                    </tr>
                </tfoot>
            </table>
            <?php if($this->tagId == 0  && !empty($this->tagList)) echo $this->paginationControl($this->tagList,'Elastic','pagebar.phtml'); ?>
        </div>
        <div id="tabs-2" class="editor-area">
            <form action="/backend/edit/tag/" method="post" onsubmit="return submitForm();">
                <div class="titlebox">
                    <h3><span>标签</span></h3>
                    <input type="text" class="title" id="tag_name" name="tag_name" autocomplete="off" tabindex="1" size="30" value="<?php echo $this->escape($this->tagInfo->tagName) ?>" />
                </div>
                <div id="message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="修改" name="publish"/>
                    <input id="tagId" name="tagId" type="hidden" value="<?php echo $this->escape($this->tagInfo->tagId) ?>" />
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#tabs").tabs({
<?php if($this->tagId > 0): ?>
            disabled: [0],
<?php else: ?>
            disabled: [1],
<?php endif; ?>
            collapsible: true
        });
    });

    function submitForm(){
        if ($("#tag_name").val() == '') {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入标签!");
            return false;
        } else {
            return true;
        }
    }

    function editTag(id){
        $("#tabs").tabs('option', 'disable', []);
        window.location.href = '/backend/list/tag/id/'+ id + '#tabs-' + 2;
    }
</script>
<?php echo $this->render('footer.phtml'); ?>